#import "AppDelegate.h"

#import <React/RCTBridge.h>
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
#import "AnimationViewController.h"
#import <CodePush.h>
#import "RNSplashScreen.h"

@interface AppDelegate ()
@property (nonatomic, strong) AnimationViewController *animationViewController;
@property (nonatomic, strong) UIViewController *rootViewController;
@end

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
  RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
  RCTRootView *rootView = [[RCTRootView alloc] initWithBridge:bridge
                                                   moduleName:@"RNProject"
                                            initialProperties:nil];

  rootView.backgroundColor = [[UIColor alloc] initWithRed:1.0f green:1.0f blue:1.0f alpha:1];

  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  self.rootViewController = [UIViewController new];
  self.rootViewController.view = rootView;
  self.window.rootViewController = self.rootViewController;
//  self.window.rootViewController = self.animationViewController;
  [self.window makeKeyAndVisible];
  [RNSplashScreen show];
  return YES;
}

- (AnimationViewController *)animationViewController{
    if (!_animationViewController) {
        _animationViewController = [[AnimationViewController alloc]init];
       //设置本地视频路径
      __weak __typeof(self) weakSelf = self;
        _animationViewController.moviePath = [[NSBundle mainBundle] pathForResource:@"splash" ofType:@"mp4"];
        _animationViewController.playFinished = ^{
            [UIApplication sharedApplication].keyWindow.rootViewController = weakSelf.rootViewController;
//          [UIView transitionWithView:[UIApplication sharedApplication].keyWindow duration:0.5f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
//            [UIApplication sharedApplication].keyWindow.rootViewController = weakSelf.rootViewController;
//          } completion:nil];
        };
    }
    return _animationViewController;
}

- (NSURL *)sourceURLForBridge:(RCTBridge *)bridge
{
#if DEBUG
  return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index" fallbackResource:nil];
#else
  return [CodePush bundleURL];
#endif
}

@end
